package com.ruoyi.activiti.service.impl;

import com.ruoyi.activiti.domain.ActWorkflowFormData;
import com.ruoyi.activiti.domain.dto.WorkflowTrajectory;
import com.ruoyi.activiti.mapper.WorkflowTrajectoryMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.manager.MyActivitiManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批轨迹Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@Service
public class WorkflowTrajectoryService
{
    @Autowired
    private WorkflowTrajectoryMapper workflowTrajectoryMapper;

    @Autowired
    private MyActivitiManager myActivitiManager;

    /**
     * 查询审批轨迹
     *
     * @param id 审批轨迹ID
     * @return 审批轨迹
     */
    public WorkflowTrajectory selectWorkflowTrajectoryById(Integer id)
    {
        return workflowTrajectoryMapper.selectWorkflowTrajectoryById(id);
    }

    /**
     * 查询审批轨迹列表
     *
     * @param workflowTrajectory 审批轨迹
     * @return 审批轨迹
     */
    public List<WorkflowTrajectory> selectWorkflowTrajectoryList(WorkflowTrajectory workflowTrajectory)
    {
        return workflowTrajectoryMapper.selectWorkflowTrajectoryList(workflowTrajectory);
    }

    /**
     * 新增审批轨迹
     *
     * @param workflowTrajectory 审批轨迹
     * @return 结果insertWorkflowTrajectory
     */
    public int insertWorkflowTrajectory(WorkflowTrajectory workflowTrajectory)
    {
        workflowTrajectory.setCreateTime(DateUtils.getNowDate());
        return workflowTrajectoryMapper.insertWorkflowTrajectory(workflowTrajectory);
    }

    /**
     * 修改审批轨迹
     *
     * @param workflowTrajectory 审批轨迹
     * @return 结果
     */
    public int updateWorkflowTrajectory(WorkflowTrajectory workflowTrajectory)
    {
        return workflowTrajectoryMapper.updateWorkflowTrajectory(workflowTrajectory);
    }

    /**
     * 批量删除审批轨迹
     *
     * @param ids 需要删除的审批轨迹ID
     * @return 结果
     */
    public int deleteWorkflowTrajectoryByIds(Integer[] ids)
    {
        return workflowTrajectoryMapper.deleteWorkflowTrajectoryByIds(ids);
    }

    /**
     * 删除审批轨迹信息
     *
     * @param id 审批轨迹ID
     * @return 结果
     */
    public int deleteWorkflowTrajectoryById(Integer id)
    {
        return workflowTrajectoryMapper.deleteWorkflowTrajectoryById(id);
    }

    /**
     * 保存轨迹信息
     * @param acwfds
     * @return
     */
    public void saveTrajectory(List<ActWorkflowFormData> acwfds, String processKey){
        if(acwfds.isEmpty()){
            return;
        }
        myActivitiManager.doSaveTrajectory(acwfds, processKey);
    }
}
